package cn.walnut.controller;

import cn.walnut.domain.FileInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.Date;

/**
 * @program: walnut-security
 * @Date: 2018/12/19 14:30
 * @Author: Walnut1992
 * @Description:
 */
@RestController
@RequestMapping("/file")
public class FileController {
    String folder = "E:/WALNUT/walnut-security/walnut-security-demo/src/main/java/cn/walnut/controller";
    @PostMapping
    public FileInfo upload(MultipartFile file) throws Exception{

        System.out.println(file.getName());
        System.out.println(file.getSize());
        System.out.println(file.getOriginalFilename());
        File file1 = new File(folder, new Date().getTime() + ".txt");
        file.transferTo(file1);
        return new FileInfo(file1.getPath());
    }

    @GetMapping("/{id}")
    public void download(@PathVariable String id, HttpServletRequest request, HttpServletResponse response) throws Exception{
    }
}
